package com.coin900.coin.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitTopicConfig {

    final static String MESSAGE = "etherdb.transactions";

//    final static String MESSAGES = "etherdb.transaction.s";

    final static String NAME = "hutch";

    @Bean
    public Queue queueMessage() {
        return new Queue(RabbitTopicConfig.MESSAGE);
    }

//    @Bean
//    public Queue queueMessages() {
//        return new Queue(RabbitTopicConfig.MESSAGES);
//    }

    /**
     * 交换机(Exchange) 描述：接收消息并且转发到绑定的队列，交换机不存储消息
     */
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(NAME);
    }

    /**
     * 綁定队列 queueMessages() 到 topicExchange 交换机,路由键只接受完全匹配 etherdb.transaction 的队列接受者可以收到消息
     *
     * @return
     */
    @Bean
    Binding bindingExchangeMessage(Queue queueMessage, TopicExchange topicExchange) {
        return BindingBuilder.bind(queueMessage).to(topicExchange).with(MESSAGE);
    }

    /**
     * 綁定队列 queueMessages() 到 topicExchange 交换机,路由键只要是以 etherdb.transaction.s 开头的队列接受者可以收到消息
     * @return
     */
//    @Bean
//    Binding bindingExchangeMessages(Queue queueMessages, TopicExchange topicExchange) {
//        return BindingBuilder.bind(queueMessages).to(topicExchange).with("topic.message.#");
//    }
}